<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>数组</title>
	<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
</head>
<body>
<script>
	var arr = [1,2,3.24,"Hello",null,true];
	console.log("arr.length:" + arr.length);
	//直接给数组的长度赋值回导致数组长度的变化
	arr.length = 3;
	console.log(`arr = ${arr}`);
	arr.length = 7;
	console.log("arr:" + arr);
	//修改arr某索引下的数值。
	arr[4] = 8;
	console.log("arr:" + arr);
	arr = [1.2,true,45];
	console.log("arr:" + arr);
	arr[5] = "ouyang";
	console.log("arr" + arr);
	//indexOf 搜索指定元素的位置
	var arr1 = [19,20,"30","xyz"];
	var index1 = arr1.indexOf(19);
	var index2 = arr1.indexOf("xyz");
	console.log("index1:" + index1 + ",index12:" + index2);
	//slice 对应string的substring()截取Array的部分元素，返回array
	var arr3 = ['A','B','C','D','E','F','G'];
	console.log("arr3.slice(0,3):" + arr3.slice(0,3));
	console.log("arr3.slice(3):" + arr3.slice(3));
	//利用Array的slice方法来复制一个Array
	var arr3Copy = arr3.slice();
	console.log("arr3Copy:" + arr3Copy);
	//push:向array的尾部添加元素
	arr3.push(1);
	arr3.push(2);
	arr3.push(3);
	console.log("arr3:" + arr3);
	//pop:从array的尾部移除元素
	arr3.pop();
	arr3.pop();
	arr3.pop();
	console.log("arr3:" + arr3);
	//unshift:往array头部添加元素;
	arr3.unshift("中国");
	arr3.unshift("美国");
	console.log("arr3:" + arr3);
	//shift:从头部移除元素
	arr3.shift();
	console.log("arr3:" + arr3)
	//sort:对array进行排序
	arr3[4] = '5';
	//var sort = arr3.sort();
	//console.log("arr3:" + arr3 + "sort:" + sort);
	arr3.reverse();
	console.log("arr3:" + arr3);
	arr3.reverse();
	console.log("arr3:" + arr3)
	//从指定位置删除，并添加若干个元素
	arr3.splice(0,2,"韩国","日本","朝鲜");
	console.log("arr3:" + arr3);
	//从指定位置删除4个元素，不添加元素
	arr3.splice(5,6);
	console.log("arr3:" + arr3);
	//从指定位置添加若干个元素;
	arr3.splice(2,0,"越南","印度");
	console.log("arr3:" + arr3)
	//concat拼接两个array
	var arr4 = [1,2,3];
	var arr5 = [4,5,6];
	var added = arr4.concat(arr5);
	console.log("added:" + added);
	//join方法把每个元素通过指定字符连接起来
	var joinArr4 = arr4.join(">_<");
	console.log("joinArr4:" + joinArr4)
	//多维数组
	var multiArr = [[1,2,3],["a","b","c"],[true,false]];
	console.log("multiArr:" + multiArr);
	console.log("multiArr[4][4]:" + multiArr[2][1]);
</script>
</body>
</html>